﻿using AutoMapper;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using Ross.EntityFramework;
using Ross.EntityFramework.Model;
using Ross.Service.Dto;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace Ross.Service
{
    public class BSCReports_DPService : BaseService, IDisposable
    {
        private TranDbContext dbContext;
        public IRepository<Targets, int> repository_T;
        public IRepository<History, int> repository_H;
        public IRepository<Users, int> userresp;
        private ResultDto<List<Dto.BSCReports_Dp>> results = new ResultDto<List<Dto.BSCReports_Dp>>();
        private TargetService targetService;
        public BSCReports_DPService(string nameOrConnectionString)
        {
            results.datas = new List<BSCReports_Dp>();
            dbContext = new TranDbContext(nameOrConnectionString);
            repository_T = new Repository<Targets, int>(dbContext);
            repository_H = new Repository<History, int>(dbContext);
            userresp = new Repository<Users, int>(dbContext);
            targetService = new TargetService(nameOrConnectionString);
        }

        public void Dispose()
        {
            dbContext.Dispose();
        }

        public ResultDto<List<Dto.BSCReports_Dp>> GetTreeList(string version = "", string name = "")
        {
            ResultDto<List<Dto.BSCReports_Dp>> result = new ResultDto<List<Dto.BSCReports_Dp>>();
            List<Dto.BSCReports_Dp> trees = new List<BSCReports_Dp>();
            List<Dto.BSCReports_Dp> zhanlue = new List<BSCReports_Dp>();
            if (string.IsNullOrEmpty(name))
            {
                name = username;
            }
            var user = userresp.GetAllList(o => o.UserName == name || o.EmpID == name).FirstOrDefault();
            string[] adepts = user.AuthorizedDepartment.Split(',');
            var lists_t = new List<Targets>();
            var lists_h = new List<History>();
            if (!string.IsNullOrEmpty(version))
            {
                lists_h = repository_H.GetAllList(o => o.Version == version).ToList();
                var resp = GetTargetsTree(lists_h);
                var tree = resp.Where(o => o.StartingTime.Year == year && adepts.Contains(o.Department)).ToList();
                if (tree.Count > 0)
                    result.datas = tree;
                else
                    result.message = $"未查询到{year}年数据";
            }
            else
            {
                var tree = new List<BSCReports_Dp>();
                lists_t = repository_T.GetAllList().ToList();
                var resp = GetTargetsTree(lists_t);
                tree = resp.Where(o => o.StartingTime.Year == year && adepts.Contains(o.Department)).ToList();
                if (tree.Count > 0)
                    result.datas = tree;
                else
                    result.message = $"未查询到{year}年数据";
            }
            return result;
        }

        /// <summary>
        /// 创建目标任务树
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="parentid"></param>
        /// <returns></returns>
        private List<Dto.BSCReports_Dp> GetTargetsTree(List<Targets> datas, int parentid = 0)
        {
            List<Dto.BSCReports_Dp> result = new List<Dto.BSCReports_Dp>();
            var lists = datas.Where(o => o.ParentTargetID == parentid).ToList();
            foreach (var item in lists)
            {
                Dto.BSCReports_Dp obj = new Dto.BSCReports_Dp();
                obj = Mapper.Map<Dto.BSCReports_Dp>(item);
                var childrens = datas.Where(o => o.ParentTargetID == item.ID).ToList();
                if (childrens.Count > 0)
                {
                    obj.Child = GetTargetsTree(datas, item.ID);
                }
                result.Add(obj);
            }
            return result;
        }
        /// <summary>
        /// 创建目标任务树
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="parentid"></param>
        /// <returns></returns>
        private List<Dto.BSCReports_Dp> GetTargetsTree(List<History> datas, int parentid = 0)
        {
            List<Dto.BSCReports_Dp> result = new List<Dto.BSCReports_Dp>();
            var lists = datas.Where(o => o.ParentTargetID == parentid).ToList();
            foreach (var item in lists)
            {
                Dto.BSCReports_Dp obj = new Dto.BSCReports_Dp();
                obj = Mapper.Map<Dto.BSCReports_Dp>(item);
                var childrens = datas.Where(o => o.ParentTargetID == item.SourceID).ToList();
                if (childrens.Count > 0)
                {
                    obj.Child = GetTargetsTree(datas, item.SourceID);
                }
                result.Add(obj);
            }
            return result;
        }
        /// <summary>
        /// 部门报表
        /// </summary>
        /// <returns></returns>
        public ResultDto<List<BSCReports_DpOut>> GetReports(string version = "", string name = "")          
        {
            ResultDto<List<BSCReports_DpOut>> result = new ResultDto<List<BSCReports_DpOut>>();
            result.datas = new List<BSCReports_DpOut>();
            try
            {
                Expression<Func<History, bool>> expr = o => o.ID > 0;
                if(!string.IsNullOrEmpty(version))
                {
                    expr = expr.ExpressionAnd(o => o.Version == version);
                }
                var datas = repository_H.GetAllList(expr).ToList();             
                //var depts = targetService.GetDeptAsync();
                var zhanlue = datas.Where(o => o.Depth == 0);
                
                foreach (var item in zhanlue)
                {
                    var plan1 = datas.Where(o => o.Depth == 1 && o.ParentTargetID == item.ID);
                    foreach(var item1 in plan1)
                    {
                        var plan2 = datas.Where(o => o.Depth == 2 && o.ParentTargetID == item1.ID);
                        foreach (var item2 in plan2)
                        {
                            var plan3 = datas.Where(o => o.Depth == 3 && o.ParentTargetID == item2.ID);
                            foreach (var item3 in plan3)
                            {
                                BSCReports_DpOut obj = new BSCReports_DpOut();
                                obj.ApprovalStatus = item.ApprovalStatus;
                                obj.AssessmentCriteria = item.AssessmentCriteria;
                                obj.Budget = (item.Budget1 + item.Budget2 + item.Budget3).ToString();
                                obj.Classification = item.Classification;
                                obj.CompletionCriteria = item.CompletionCriteria;
                                obj.Department = item.Department;
                                obj.DepartmentTarget = item.TargetName;
                                obj.Lock = item.Lock;
                                obj.TargetCenter = item.TargetCenter;
                                obj.TargetName = item.TargetName;
                                obj.TargetState = item.TargetState;
                                obj.TargetTeam = item.TargetTeam;

                                obj.content1 = item1.TargetName;
                                obj.CompletionCriteria1 = item1.CompletionCriteria;
                                obj.StartingTime1 = item1.StartingTime;
                                obj.ActualCompletionTime1 = item1.ActualCompletionTime;
                                obj.PlannedCompletionTime1 = item1.PlannedCompletionTime;
                                obj.Responsible1 = item1.Responsible;
                                obj.AccountingMethod1 = item1.AccountingMethod;
                                obj.Statistician1 = item1.Statistician;
                                obj.ResourceSupport1 = item1.ResourceSupport;
                                obj.progress1 = "";

                                obj.content2 = item2.TargetName;
                                obj.CompletionCriteria2 = item2.CompletionCriteria;
                                obj.StartingTime2 = item2.StartingTime;
                                obj.ActualCompletionTime2 = item2.ActualCompletionTime;
                                obj.PlannedCompletionTime2 = item2.PlannedCompletionTime;
                                obj.Responsible2 = item2.Responsible;
                                obj.AccountingMethod2 = item2.AccountingMethod;
                                obj.Statistician2 = item2.Statistician;
                                obj.ResourceSupport2 = item2.ResourceSupport;
                                obj.progress2 = "";

                                obj.content3 = item3.TargetName;
                                obj.CompletionCriteria3 = item3.CompletionCriteria;
                                obj.StartingTime3 = item3.StartingTime;
                                obj.ActualCompletionTime3 = item3.ActualCompletionTime;
                                obj.PlannedCompletionTime3 = item3.PlannedCompletionTime;
                                obj.Responsible3 = item3.Responsible;
                                obj.AccountingMethod3 = item3.AccountingMethod;
                                obj.Statistician3 = item3.Statistician;
                                obj.ResourceSupport3 = item3.ResourceSupport;
                                result.datas.Add(obj);
                            }
                        }
                    }
                }
                result.datas = result.datas.Where(o => o.ApprovalStatus == "已审核" && o.Lock == true).ToList();
            }
            catch (Exception e)
            {
                result.status = 500;
                result.message = e.Message;
            }
            return result;
        }

        /// <summary>
        /// 导出部门级报表
        /// </summary>
        /// <returns></returns>
        public FileResult ExportExcel_Dp(string version = "", string name = "")
        {
            //ResultDto<FileResult> result = new ResultDto<FileResult>();
            try
            {
                HSSFWorkbook book = new HSSFWorkbook();
                ISheet sheet1 = book.CreateSheet("Sheet1");
                //设置列宽
                for (int i = 0; i < 30; i++)
                    sheet1.SetColumnWidth(i, 4000);
                //标题设置
                IRow row0 = sheet1.CreateRow(0);
                row0.HeightInPoints = 30;
                IFont fontTitle = book.CreateFont();
                fontTitle.FontHeightInPoints = 18;
                fontTitle.Boldweight = (short)FontBoldWeight.Bold;
                //设置单元格边框
                ICellStyle styleTiltle = book.CreateCellStyle();
                styleTiltle.Alignment = HorizontalAlignment.Center;
                styleTiltle.SetFont(fontTitle);
                styleTiltle.VerticalAlignment = VerticalAlignment.Center;
                IFont fontContent = book.CreateFont();
                fontContent.FontHeightInPoints = 14;
                ICellStyle styleContent = book.CreateCellStyle();
                styleContent.Alignment = HorizontalAlignment.Center;
                styleContent.SetFont(fontContent);
                styleContent.VerticalAlignment = VerticalAlignment.Center;
                string currxzq = "BSC报表-部门级";
                row0.CreateCell(0).SetCellValue(currxzq);
                sheet1.AddMergedRegion(new CellRangeAddress(0, 0, 0, 30));
                row0.GetCell(0).CellStyle = styleTiltle;

                //设置内容单元格
                string[] colums = ("分类|战略目标|部门目标|中心|部门|团队|考核基准|措施分解").Split('|');
                IRow row1 = sheet1.CreateRow(1);
                for (int i = 0; i < colums.Length; i++)
                {
                    if (i < 7)
                    {
                        row1.CreateCell(i).SetCellValue(colums[i]);
                        sheet1.AddMergedRegion(new CellRangeAddress(1, 3, i, i));
                        row1.GetCell(i).CellStyle = styleContent;
                    }
                    if (i==7)
                    {
                        row1.CreateCell(i).SetCellValue(colums[i]);
                        sheet1.AddMergedRegion(new CellRangeAddress(1, 1, 7, 30));
                        row1.GetCell(i).CellStyle = styleContent;
                    }
                    //if (i>=7)
                    //{
                    //    row1.CreateCell(i+23).SetCellValue(colums[i]);
                    //    sheet1.AddMergedRegion(new CellRangeAddress(1, 3, i + 23, i + 23));
                    //    row1.GetCell(i+23).CellStyle = styleContent;
                    //}


                }
                IRow row2 = sheet1.CreateRow(2);
                string[] colums2 = ("一级计划|二级计划|三级计划").Split('|');
                for (int i = 0; i < colums2.Length; i++)
                {
                    row2.CreateCell(7 + i * 8).SetCellValue(colums2[i]);
                    sheet1.AddMergedRegion(new CellRangeAddress(2, 2, 7 + i * 8, 14 + i * 8));
                    row2.GetCell(7 + i * 8).CellStyle = styleContent;
                }
                IRow row3 = sheet1.CreateRow(3);
                string[] colums3 = ("计划内容|完成标准|责任人|核算方式|统计人|开始时间|结束时间|资源支持|计划内容|完成标准|责任人|核算方式|统计人|开始时间|结束时间|资源支持|计划内容|完成标准|责任人|核算方式|统计人|开始时间|结束时间|资源支持").Split('|');
                for (int i = 0; i < colums3.Length; i++)
                {
                    row3.CreateCell(7 + i).SetCellValue(colums3[i]);
                    sheet1.AddMergedRegion(new CellRangeAddress(3, 3, 7 + i, 7 + i));
                    row3.GetCell(7 + i).CellStyle = styleContent;
                }
                //填写数据
                ResultDto<List<BSCReports_DpOut>> list = new ResultDto<List<BSCReports_DpOut>>();
                list = GetReports(version, name);
                List<BSCReports_DpOut> datas = new List<BSCReports_DpOut>();
                datas = list.datas;
                IFont fontContent2 = book.CreateFont();
                fontContent2.FontHeightInPoints = 12;
                ICellStyle styleContent2 = book.CreateCellStyle();
                styleContent2.Alignment = HorizontalAlignment.Center;
                styleContent2.SetFont(fontContent2);
                styleContent2.VerticalAlignment = VerticalAlignment.Center;
                if (datas.Count > 0)
                {
                    for (int i = 0; i < datas.Count; i++)
                    {
                        IRow row4 = sheet1.CreateRow(i + 4);
                        //"分类|战略目标|部门目标|中心|部门|团队|考核基准
                        row4.CreateCell(0).SetCellValue(list.datas[i].Classification);
                        row4.GetCell(0).CellStyle = styleContent2;
                        row4.CreateCell(1).SetCellValue(list.datas[i].TargetName);
                        row4.GetCell(1).CellStyle = styleContent2;
                        row4.CreateCell(2).SetCellValue(list.datas[i].DepartmentTarget);
                        row4.GetCell(2).CellStyle = styleContent2;
                        row4.CreateCell(3).SetCellValue(list.datas[i].TargetCenter);
                        row4.GetCell(3).CellStyle = styleContent2;
                        row4.CreateCell(4).SetCellValue(list.datas[i].Department);
                        row4.GetCell(4).CellStyle = styleContent2;
                        row4.CreateCell(5).SetCellValue(list.datas[i].TargetTeam);
                        row4.GetCell(5).CellStyle = styleContent2;
                        row4.CreateCell(6).SetCellValue(list.datas[i].AssessmentCriteria);
                        row4.GetCell(6).CellStyle = styleContent2;
                        //"计划内容|完成标准|责任人|核算方式|统计人|开始时间|结束时间|资源支持|
                        row4.CreateCell(7).SetCellValue(list.datas[i].content1);
                        row4.GetCell(7).CellStyle = styleContent2;
                        row4.CreateCell(8).SetCellValue(list.datas[i].CompletionCriteria1);
                        row4.GetCell(8).CellStyle = styleContent2;
                        row4.CreateCell(9).SetCellValue(list.datas[i].Responsible1);
                        row4.GetCell(9).CellStyle = styleContent2;
                        row4.CreateCell(10).SetCellValue(list.datas[i].AccountingMethod1);
                        row4.GetCell(10).CellStyle = styleContent2;
                        row4.CreateCell(11).SetCellValue(list.datas[i].Statistician1);
                        row4.GetCell(11).CellStyle = styleContent2;
                        if (list.datas[i].StartingTime1 == Convert.ToDateTime("0001-01-01") || list.datas[i].StartingTime1 == null)
                            row4.CreateCell(12).SetCellValue("");
                        else
                            row4.CreateCell(12).SetCellValue(((DateTime)list.datas[i].StartingTime1).ToString("yyyy/MM/dd"));
                        row4.GetCell(12).CellStyle = styleContent2;
                        if (list.datas[i].ActualCompletionTime1 == Convert.ToDateTime("0001-01-01") || list.datas[i].ActualCompletionTime1 == null)
                            row4.CreateCell(13).SetCellValue("");
                        else
                            row4.CreateCell(13).SetCellValue(((DateTime)list.datas[i].ActualCompletionTime1).ToString("yyyy/MM/dd"));
                        row4.GetCell(13).CellStyle = styleContent2;
                        row4.CreateCell(14).SetCellValue(list.datas[i].ResourceSupport1);
                        row4.GetCell(14).CellStyle = styleContent2;

                        row4.CreateCell(15).SetCellValue(list.datas[i].content2);
                        row4.GetCell(15).CellStyle = styleContent2;
                        row4.CreateCell(16).SetCellValue(list.datas[i].CompletionCriteria2);
                        row4.GetCell(16).CellStyle = styleContent2;
                        row4.CreateCell(17).SetCellValue(list.datas[i].Responsible2);
                        row4.GetCell(17).CellStyle = styleContent2;
                        row4.CreateCell(18).SetCellValue(list.datas[i].AccountingMethod2);
                        row4.GetCell(18).CellStyle = styleContent2;
                        row4.CreateCell(19).SetCellValue(list.datas[i].Statistician2);
                        row4.GetCell(19).CellStyle = styleContent2;
                        if (list.datas[i].StartingTime2 == Convert.ToDateTime("0001-01-01") || list.datas[i].StartingTime2 == null)
                            row4.CreateCell(20).SetCellValue("");
                        else
                            row4.CreateCell(20).SetCellValue(((DateTime)list.datas[i].StartingTime2).ToString("yyyy/MM/dd"));
                        row4.GetCell(20).CellStyle = styleContent2;
                        if (list.datas[i].ActualCompletionTime2 == Convert.ToDateTime("0001-01-01") || list.datas[i].ActualCompletionTime2 == null)
                            row4.CreateCell(21).SetCellValue("");
                        else
                            row4.CreateCell(21).SetCellValue(((DateTime)list.datas[i].ActualCompletionTime2).ToString("yyyy/MM/dd"));
                        row4.GetCell(21).CellStyle = styleContent2;

                        row4.CreateCell(22).SetCellValue(list.datas[i].ResourceSupport2);
                        row4.GetCell(22).CellStyle = styleContent2;

                        row4.CreateCell(23).SetCellValue(list.datas[i].content3);
                        row4.GetCell(23).CellStyle = styleContent2;
                        row4.CreateCell(24).SetCellValue(list.datas[i].CompletionCriteria3);
                        row4.GetCell(24).CellStyle = styleContent2;
                        row4.CreateCell(25).SetCellValue(list.datas[i].Responsible3);
                        row4.GetCell(25).CellStyle = styleContent2;
                        row4.CreateCell(26).SetCellValue(list.datas[i].AccountingMethod3);
                        row4.GetCell(26).CellStyle = styleContent2;
                        row4.CreateCell(27).SetCellValue(list.datas[i].Statistician3);
                        row4.GetCell(27).CellStyle = styleContent2;
                        if (list.datas[i].StartingTime3 == Convert.ToDateTime("0001-01-01") || list.datas[i].StartingTime3 == null)
                            row4.CreateCell(28).SetCellValue("");
                        else
                            row4.CreateCell(28).SetCellValue(((DateTime)list.datas[i].StartingTime3).ToString("yyyy/MM/dd"));
                        row4.GetCell(28).CellStyle = styleContent2;

                        if (list.datas[i].ActualCompletionTime3 == Convert.ToDateTime("0001-01-01") || list.datas[i].ActualCompletionTime3 == null)
                            row4.CreateCell(29).SetCellValue("");
                        else
                            row4.CreateCell(29).SetCellValue(((DateTime)list.datas[i].ActualCompletionTime3).ToString("yyyy/MM/dd"));
                        row4.GetCell(29).CellStyle = styleContent2;

                        row4.CreateCell(30).SetCellValue(list.datas[i].ResourceSupport3);
                        row4.GetCell(30).CellStyle = styleContent2;

                        //row4.CreateCell(30).SetCellValue(list.datas[i].Budget);
                        //row4.GetCell(30).CellStyle = styleContent2;
                    }
                    //返回文件流至前台
                    MemoryStream ms = new MemoryStream();
                    book.Write(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    FileStreamResult file = new FileStreamResult(ms, "application/vnd.ms-excel");
                    file.FileDownloadName = "BSC部门报表" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                    return file;
                }

            }
            catch (Exception e)
            {
                //result.status = 500;
                //result.message = e.Message;
                //throw;
            }
            return null;
        }

        /// <summary>
        /// 更新状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="ApprovalStatus"></param>
        /// <returns></returns>
        public ResultDto<bool> UpdateApprovalStatus(int id, string ApprovalStatus)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            try
            {
                var bumen = repository_T.Get(id);
                bumen.ApprovalStatus = ApprovalStatus;
                repository_T.Update(bumen);
                List<int> idss = new List<int>();
                idss = ids(bumen, idss);
                foreach (var item in idss)
                {
                    var child = repository_T.Get(item);
                    child.ApprovalStatus = ApprovalStatus;
                    repository_T.Update(child);
                }
                result.datas = true;
                return result;
            }
            catch (Exception)
            {
                result.datas = false;
            }
            return result;
        }

        List<int> ids(Targets targets, List<int> idss)
        {
            var child = repository_T.GetAllList(o => o.ParentTargetID == targets.ID);
            if(child!=null)
            {
                foreach (var item in child)
                {
                    idss.Add(item.ID);
                    ids(item, idss);
                }
            }
            return idss;
        }

        public ResultDto<List<string>> GetVersion()
        {
            List<string> ver = new List<string>();
            ResultDto<List<string>> result = new ResultDto<List<string>>();
            try
            {
                var user = userresp.GetAllList(o => o.UserName == username || o.EmpID == username).FirstOrDefault();
                string[] adepts = user.AuthorizedDepartment.Split(',');
                var list = repository_H.GetAllList(o => o.ParentTargetID == -1 && o.TargetName == year.ToString() && adepts.Contains(o.Department));
                foreach (var item in list)
                {
                    ver.Add(item.Version);
                }
                result.datas = ver;
                return result;
            }
            catch (Exception e)
            {
                result.status = 500;
                result.message = e.Message;
            }
            return result;
        }


        public ResultDto<List<ShenHeOutput>> ChaXunShenHe()
        {
            var result = new ResultDto<List<ShenHeOutput>>();

            //查询计划  深度>=4 审核中
            var t = repository_T.GetAllList(o => o.Depth >= 4 & o.ApprovalStatus == "审核中");
            var t1 = repository_T.GetAllList();
            var datas = Mapper.Map<List<ShenHeBiao>>(t1);

            var lists = Mapper.Map<List<ShenHeBiao>>(t);
            //查询后显示整颗树
            foreach(var i in lists )
            {
                i.Child = null;
                GetTargets(datas, i);
            }
            var outputs = new List<ShenHeOutput>();
            //遍历集合，按深度从每个节点取值
            foreach(var j in lists)
            {
                var output = new ShenHeOutput();
                var res= GetShenHe(j, output);
                outputs.Add(res);
            }

            result.datas = outputs;
            result.status = 200;
            return result;
        }

        // 遍历每个节点取值
        private ShenHeOutput GetShenHe(ShenHeBiao shenHe,ShenHeOutput t)
        {

            if (shenHe.Child!=null)
            {
                
                if(shenHe.Depth==1)
                {
                    //取分类
                    t.FenLeiTargetName = shenHe.TargetName;
                }
                if(shenHe.Depth==2)
                {
                    //取战略目标
                    t.ZhanLueTargetName = shenHe.TargetName;
                }
                if(shenHe.Depth==3)
                {
                    //取部门目标
                    t.BuMenTargetName = shenHe.TargetName;
                }
                if(shenHe.Depth==4)
                {
                    //取计划1
                    t.JiHuaTargetName1 = shenHe.TargetName;
                    t.JiHuaResponsible1 = shenHe.Responsible;
                    t.JiHuaStartingTime1 = shenHe.StartingTime;
                    t.JiHuaPlannedCompletionTime1 = shenHe.PlannedCompletionTime;
                }
                if (shenHe.Depth == 5)
                {
                    //计划2
                    t.JiHuaTargetName2 = shenHe.TargetName;
                    t.JiHuaResponsible2 = shenHe.Responsible;
                    t.JiHuaStartingTime2 = shenHe.StartingTime;
                    t.JiHuaPlannedCompletionTime2 = shenHe.PlannedCompletionTime;
                }
                if (shenHe.Depth == 6)
                {
                    //计划3
                    t.JiHuaTargetName3 = shenHe.TargetName;
                    t.JiHuaResponsible3 = shenHe.Responsible;
                    t.JiHuaStartingTime3 = shenHe.StartingTime;
                    t.JiHuaPlannedCompletionTime3 = shenHe.PlannedCompletionTime;
                }
            }

             t= GetShenHe(shenHe.Child, t);
            return t;
        }


        //向上查当前节点的一条路径
        //给我一个ID
        private ShenHeBiao GetTargets(List<ShenHeBiao> datas, ShenHeBiao nodes)
        {
            if (nodes.ParentTargetID == -1)
                return nodes;
               
            //他的父节点
            var lists = datas.Where(u => u.ID == nodes.ParentTargetID).ToList().First();

            //加入子节点
            lists.Child = nodes;

            GetTargets(datas, lists);

            return nodes;
        }

        bool Panduan(DateTime dateTime)
        {
            if (dateTime == Convert.ToDateTime("0001-01-01"))
            {
                return true;
            }
            else
                return false;
        }

    }
}
